import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';

import 'cell/cell.dart';
import 'gaps.dart';

class CardView extends StatelessWidget {
  final EdgeInsetsGeometry? padding;
  final EdgeInsetsGeometry? margin;
  final Color background;
  final BorderRadius borderRadius;
  final double borderWidth;
  final Color borderColor;
  final Color? boxShadowColor;
  final Widget? child;
  final Widget? titleView;

  const CardView({
    super.key,
    this.background = Colors.transparent,
    this.borderRadius = BorderRadius.zero,
    this.borderWidth = 0,
    this.borderColor = Colors.transparent,
    this.boxShadowColor,
    this.child,
    this.padding = const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
    this.margin = const EdgeInsets.symmetric(horizontal: 16.0),
    this.titleView,
  });

  CardView.title(
    String? title, {
    super.key,
    String? subTitle,
        bool isMust = false,
    TextStyle titleStyle = const TextStyle(fontSize: 16.0, color: Colors.black),
    TextStyle subTitleStyle = const TextStyle(fontSize: 14.0, color: Colors.blueGrey),
    double? titleWidth,
    TextAlign textAlign = TextAlign.end,
    bool isShowBottomLine = false,
    Color? bottomLineColor,
    double? bottomLineWidth,
    GestureTapCallback? onTitleTap,
    this.background = Colors.transparent,
    this.borderRadius = BorderRadius.zero,
    this.borderWidth = 0,
    this.borderColor = Colors.transparent,
    this.boxShadowColor,
    this.child,
    this.padding = const EdgeInsets.symmetric(horizontal: 0.0, vertical: 0.0),
    this.margin = const EdgeInsets.symmetric(horizontal: 0.0),
    EdgeInsetsGeometry titlePadding = const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
    EdgeInsetsGeometry titleMargin = const EdgeInsets.symmetric(horizontal: 16.0),
    Color titleBackground = Colors.transparent,
    Widget? titleRightWidget,
  }) : this.titleView = ObjectUtil.isEmpty(title)
            ? null
            : Container(
                child: AppLabelCell.title(
                  title: title ?? '',
                  subTitle: subTitle ?? '',
                  titleStyle: titleStyle,
                  subTitleStyle: subTitleStyle,
                  isShowBottomLine: isShowBottomLine,
                  isMust:isMust,
                  padding: titlePadding,
                  background: titleBackground,
                  margin: titleMargin,
                  titleWidth: titleWidth,
                  textAlign: textAlign,
                  bottomLineColor: bottomLineColor,
                  bottomLineWidth: bottomLineWidth,
                  onTap: onTitleTap,
                  rightWidget: titleRightWidget,
                ),
              );

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: padding,
      margin: margin,
      decoration: BoxDecoration(
        color: background,
        borderRadius: borderRadius,
        border: Border.all(
          color: borderColor,
          width: borderWidth,
        ),
        boxShadow: boxShadowColor == null
            ? []
            : [
                BoxShadow(
                  color: boxShadowColor!.withOpacity(0.1),
                  offset: Offset(0.0, 0.0), //阴影xy轴偏移量
                  blurRadius: 10.0, //阴影模糊程度
                  spreadRadius: 0, //阴影扩散程度
                ),
              ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          titleView ?? Gaps.empty,
          child ?? Gaps.empty,
        ],
      ),
    );
  }
}
